package servlets;

import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class HttpServlet extends GenericServlet {
    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        
        //多态：分为上转型与下转型
        //上：子类赋值给父类
        //下：父类赋值给子类，需要强转
        
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        
        service(request,response);
    }
    
    
    public void service(HttpServletRequest request, HttpServletResponse response) {
        
        //获取请求的提交方式
        String method = request.getMethod();
        if ("POST".equals(method)) {
            doPost(request,response);
        } else if ("GET".equals(method)) {
            doGet(request,response);
        }
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) {
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) {
    }
}
